package com.example.chcrm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.chcrm.entity.common.ResponseMsg;
import com.example.chcrm.entity.common.ServletUtils;
import com.example.chcrm.entity.consignor.CustomerInfo;
import com.example.chcrm.entity.employee.Department;
import com.example.chcrm.entity.employee.EmployeeVo;
import com.example.chcrm.entity.employee.EssEmployee;
import com.example.chcrm.entity.employee.RoleModels;
import com.example.chcrm.service.CustomerInfoService;
import com.example.chcrm.service.CustomerTypeService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * @Author 邹
 * @Date 2025/4/20 2:02
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/customerInfo")
@CrossOrigin // 允许跨域访问
public class CustomerInfoController {
    @Autowired
    CustomerInfoService customerInfoService;

    /**
     * 分页查询
     */
    @PostMapping("/pageList")
    public ResponseMsg<IPage<CustomerInfo>> pageList(@RequestBody CustomerInfo customerInfo) throws ParseException {
        ResponseMsg<Object> msg = new ResponseMsg<>();
        //获取登录用户信息
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerInfoService.pageList(customerInfo, empVo);
    }

    /**
     * 委托商禁用/启用/发送审核
     */
    @PostMapping("/disable")
    public ResponseMsg<Object> disable(@RequestBody CustomerInfo customerInfo) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;

        return  customerInfoService.disable(customerInfo,empVo);
    }

    /**
     * 委托商详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public ResponseMsg<Object> detail(@PathVariable String id) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerInfoService.detail(id);
    }

    /**
     * 修改委托商信息
     */
    @PostMapping("/update")
    public ResponseMsg<Object> update(@RequestBody CustomerInfo customerInfo) {
        return customerInfoService.update(customerInfo);
    }

    /**
     * 新增委托商
     */
    @PostMapping("/add")
    public ResponseMsg<Object> add(@RequestBody CustomerInfo customerInfo) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerInfoService.add(customerInfo, empVo);
    }

    /***
     * 用户导出
     * @param employee
     * @return
     * **/
    @RequestMapping("/export")
    public ModelAndView customerExport(CustomerInfo employee) {
        //获取登录用户信息
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        ModelAndView modelAndView = customerInfoService.export(employee, empVo);
        return modelAndView;

    }
}
